import * as api from '../api'

export const test = ({commit}) => {
  commit('test')
}

// 发送短信
export const smsSend = ({commit}, data) => {
  commit('RESET_STATUS')
  api.smsSend(data, msg => {
    commit('SMSSEND_SUCCESS', {msg})
  }, msg => {
    commit('SMSSEND_FAILED', {msg})
  })
}

// 获取浮点基础信息
export const getBaseInfo = ({commit}) => {
  api.getBaseInfo(data => {
    commit('GET_BASEINFO_SUCCESS', {data})
  }, msg => {
    commit('ACTION_FAILED', {msg})
  })
}

// 获取用户信息
export const getUserDetail = ({commit}) => {
  api.getUserDetail(data => {
    commit('GET_USERDETAIL_SUCCESS', {data})
  }, msg => {
    commit('ACTION_FAILED', {msg})
  })
}

// 修改密码
export const updateUserPasswd = ({commit}, data) => {
  commit('RESET_STATUS')
  api.updateUserPasswd(data, msg => {
    commit('ACTION_SUCCESS', {msg})
  }, msg => {
    commit('ACTION_FAILED', {msg})
  })
}

// 礼包列表
export const getGiftList = ({commit}, data) => {
  commit('RESET_STATUS')
  if (!data || !data.page) {
    commit('CLEAR_GIFTLIST')
  }
  api.getGiftList(data, data => {
    commit('GET_GIFTLIST_SUCCESS', {data})
  }, msg => {
    commit('ACTION_FAILED', {msg})
  })
}

// 礼包详情
export const getGiftDetail = ({commit}, id) => {
  commit('RESET_STATUS')
  api.getGiftDetail(id, data => {
    commit('GET_GIFTDETAIL_SUCCESS', {data})
  }, msg => {
    commit('ACTION_FAILED', {msg})
  })
}

// 礼包领取
export const addGift = ({commit}, id) => {
  commit('RESET_STATUS')
  api.addGift(id, data => {
    commit('ADD_GIFT_SUCCESS', {data})
  }, msg => {
    commit('ACTION_FAILED', {msg})
  })
}

// 资讯列表
export const getNewsList = ({commit}, data) => {
  commit('RESET_STATUS')
  api.getNewsList(data, data => {
    commit('GET_NEWSLIST_SUCCESS', {data})
  }, msg => {
    commit('ACTION_FAILED', {msg})
  })
}

// 资讯详情
export const getNewsDetail = ({commit}, id) => {
  commit('CLEAR_NEWSDETAIL')
  commit('RESET_STATUS')
  api.getNewsDetail(id, data => {
    commit('GET_NEWSDETAIL_SUCCESS', {data})
  }, msg => {
    commit('ACTION_FAILED', {msg})
  })
}

// 消息列表
export const getMsgList = ({commit}, data) => {
  commit('RESET_STATUS')
  if (!data || !data.page) {
    commit('CLEAR_LIST')
  }
  api.getMsgList(data, data => {
    commit('GET_MSGLIST_SUCCESS', {data})
  }, msg => {
    commit('ACTION_FAILED', {msg})
  })
}

// 代金券单游券列表
export const couponSingleList = ({commit}, data) => {
  commit('RESET_STATUS')
  api.getCouponList(data, data => {
    commit('COUPONLIST_SINGLE_SUCCESS', {data})
  }, msg => {
    commit('ACTION_FAILED', {msg})
  })
}

// 代金券通用券列表
export const couponGeneralList = ({commit}, data) => {
  commit('RESET_STATUS')
  api.getCouponList(data, data => {
    commit('COUPONLIST_GENERAL_SUCCESS', {data})
  }, msg => {
    commit('ACTION_FAILED', {msg})
  })
}

// 领取代金券
export const receiveCoupon = ({commit}, id) => {
  commit('RESET_STATUS')
  api.receiveCoupon(id, data => {
    commit('RECEIVE_COUPON_SUCCESS', {data})
  }, msg => {
    commit('ACTION_FAILED', {msg})
  })
}

// 游戏币充值记录
export const getGmRechargeList = ({commit}, data) => {
  commit('RESET_STATUS')
  if (!data || !data.page || data.page == 1) {
    commit('CLEAR_LIST')
  }
  api.getGmRechargeList(data, data => {
    commit('GET_GMRECHARGE_SUCCESS', {data})
  }, msg => {
    commit('ACTION_FAILED', {msg})
  })
}

// 充值记录
export const getOrderList = ({commit}, data) => {
  commit('RESET_STATUS')
  if (!data || !data.page || data.page == 1) {
    commit('CLEAR_LIST')
  }
  api.getOrderList(data, data => {
    commit('GET_ORDERLIST_SUCCESS', {data})
  }, msg => {
    commit('ACTION_FAILED', {msg})
  })
}

// 游戏币充值
export const gmRecharge = ({commit}) => {
  api.gmRecharge(data => {
    commit('GM_RECHARGE_SUCCESS', {data})
  }, msg => {
    commit('ACTION_FAILED', {msg})
  })
}

// 选择支付方式进行支付
export const gmPayPost = ({commit}, data) => {
  commit('RESET_STATUS')
  api.gmPayPost(data, data => {
    commit('GM_PAYPOST_SUCCESS', {data})
  }, msg => {
    commit('ACTION_FAILED', {msg})
  })
}

// 实名认证
export const setIdentify = ({commit}, data) => {
  commit('RESET_STATUS')
  api.setIdentify(data, data => {
    commit('SET_IDENTIFY_SUCCESS', {data})
  }, msg => {
    commit('ACTION_FAILED', {msg})
  })
}

// 我的小号列表
export const getAccountList = ({commit}, data) => {
  commit('RESET_STATUS')
  api.getAccountList(data => {
    commit('GET_ACCOUNTLIST_SUCCESS', {data})
  }, msg => {
    commit('ACTION_FAILED', {msg})
  })
}

// 添加小号
export const addAccount = ({commit}, nickname) => {
  commit('RESET_STATUS')
  api.addAccount(nickname, msg => {
    commit('ACTION_SUCCESS', {msg})
  }, msg => {
    commit('ACTION_FAILED', {msg})
  })
}

// 切换小号
export const switchAccount = ({commit}, id) => {
  commit('RESET_STATUS')
  api.switchAccount(id, msg => {
    commit('ACTION_SUCCESS', {msg})
  }, msg => {
    commit('ACTION_FAILED', {msg})
  })
}

// 用户密保信息
export const bindInfo = ({commit}) => {
  commit('RESET_STATUS')
  api.bindInfo(data => {
    commit('BIND_INFO_SUCCESS', {data})
  }, msg => {
    commit('ACTION_FAILED', {msg})
  })
}

// 校验原有手机
export const smsCheckold = ({commit}, data) => {
  commit('RESET_STATUS')
  api.smsCheckold(data, msg => {
    commit('ACTION_SUCCESS', {msg})
  }, msg => {
    commit('ACTION_FAILED', {msg})
  })
}

// 绑定手机
export const bindMobile = ({commit}, data) => {
  commit('RESET_STATUS')
  api.bindMobile(data, msg => {
    commit('ACTION_SUCCESS', {msg})
  }, msg => {
    commit('ACTION_FAILED', {msg})
  })
}

// 发送短信
export const fSmsSend = ({commit}, data) => {
  commit('RESET_STATUS')
  api.fSmsSend(data, msg => {
    commit('ACTION_SUCCESS', {msg})
  }, msg => {
    commit('ACTION_FAILED', {msg})
  })
}

// 找回密码发送短信
export const devSendSms = ({commit}, data) => {
  commit('RESET_STATUS')
  api.devSendSms(data, data => {
    commit('DEVICE_SENDSMS_SUCCESS', {data})
  }, msg => {
    commit('ACTION_FAILED', {msg})
  })
}
